package com.jerkin.invoke;

import com.jerkin.init.InitInterfaceInfo;
import com.jerkin.request.RpcRequest;
import lombok.SneakyThrows;

import java.lang.reflect.Method;

/**
 * @version V1.0
 * @ClassName: InvokeMethod
 * @Description:
 * @author: huhongzhi
 * @date: 2021/4/17 16:49
 */
public class InvokeMethod {

    @SneakyThrows
    public static Object invoke(RpcRequest rpcRequest) {
        String clazzName = rpcRequest.getClassName();
        //获取具体的实现
        Object serviceObject = InitInterfaceInfo.instance(clazzName);
        Class<?> clazz = InitInterfaceInfo.getInterfaceInfo(clazzName);
        Method method = clazz.getMethod(rpcRequest.getMethodName(), rpcRequest.getParameterTypes());
        return method.invoke(serviceObject, rpcRequest.getParameters());
    }

}
